package cn.shyouchi.wuguanjia.android.api;

import android.text.TextUtils;

import java.io.IOException;

import cn.shyouchi.wuguanjia.android.components.storage.UserStorage;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by Eenie on 2017/3/3 at 15:39
 * Email: 472279981@qq.com
 * Des:
 */

public class TokenInterceptor implements Interceptor {
    private UserStorage mUserStorage;
    public TokenInterceptor(UserStorage userStorage) {
        this.mUserStorage = userStorage;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();
        if (mUserStorage != null && !TextUtils.isEmpty(mUserStorage.getToken())) {
            request = request.newBuilder().addHeader("token", mUserStorage.getToken()).build();
        }
        return chain.proceed(request);
    }

}
